package com.nineclock.system.controller;

import com.nineclock.api.system.SysCompanyControllerApi;

import com.nineclock.system.service.SysCompanyService;
import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @Package: com.nineclock.system.controller
 * @ClassName: SysCompanyController
 * @Author: 小康
 * @CreateTime: 2021-06-10 17:09
 * @Description:
 */
@RestController
@RequestMapping("/company")
public class SysCompanyController implements SysCompanyControllerApi {

    @Autowired
    SysCompanyService companyService;

    //查询当前企业信息
    @Override
    @GetMapping
    public Result<SysCompanyDTO> queryCompanyInfo() {
        SysCompanyDTO companyDTO = companyService.queryCompanyInfo();
        return Result.success(companyDTO);
    }

    //上传企业logo
    @Override
    @PostMapping("/uploadOSS")
    public Result<String> uploadCompanyLogo(MultipartFile file) throws IOException {
        String logoUrl = companyService.uploadCompanyLogo(file);
        return Result.success(logoUrl);
    }

    //保存企业信息
    @Override
    @PutMapping
    public Result updateCompanyInfo(@RequestBody SysCompanyDTO sysCompanyDTO) {

        companyService.updateCompanyInfo(sysCompanyDTO);
        return Result.success();
    }
    //获取当前系统管理员信息


    @Override
    @GetMapping("/getCurrentAdmin")
    public Result<SysCompanyUserDTO> getCurrentAdmin() {
        SysCompanyUserDTO companyUserDTO = companyService.getCurrentAdmin();
        return Result.success(companyUserDTO);
    }

    //获取员工列表
    @Override
    @PostMapping("/config/admin")
    public Result changeSysAdmin(@RequestBody SysChangeMainManagerDTO sysChangeMainManagerDTO) {
        companyService.changeSysAdmin(sysChangeMainManagerDTO);
        return Result.success();
    }

    //企业模糊查询
    @Override
    @GetMapping("/list")
    public Result<List<SysCompanyDTO>> queryCompanyByName(String keyword) {
        List<SysCompanyDTO> companyDTOList = companyService.queryCompanyByName(keyword);
        return Result.success(companyDTOList);
    }

    //申请加入企业
    @Override
    @PostMapping("/applyJoinCompany")
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO sysApplyJoinCompanyUserDTO) {
        companyService.applyJoinCompany(sysApplyJoinCompanyUserDTO);
        return Result.success();

    }
    //审核加入企业
    @Override
    @PostMapping("/allowedJoinCompany")
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO sysAllowedJoinCompanyUserDTO) {
        companyService.allowedJoinCompany(sysAllowedJoinCompanyUserDTO);
        return Result.success();
    }
    /**
     *  @Date: 2021/6/24 17:25
     *  根据用户ID查询关联的企业列表
     */
    @Override
    @GetMapping("/list/{userId}")
    public Result<List<SysCompanyDTO>> queryCompanyList(@PathVariable("userId") Long userId) {
        List<SysCompanyDTO> companyDTOList = companyService.queryCompanyList(userId);
        return Result.success(companyDTOList);
    }


}
